from classfile.constant_info import ConstantInfo


class ConstantMethodHandleInfo(ConstantInfo):
    def __init__(self):
        super().__init__()
        self.referKind = None
        self.referIndex = None

    def readInfo(self, clsReader):
        self.referKind = clsReader.readU8()
        self.referIndex = clsReader.readU16()


class ConstantMethodTypeInfo(ConstantInfo):
    def __init__(self):
        super().__init__()
        self.descIndex = 0

    def readInfo(self, clsReader):
        self.descIndex = clsReader.readU16()


class ConstantInvokeDynamicInfo(ConstantInfo):
    def __init__(self):
        super().__init__()
        self.bootMethodAttrIndex = 0
        self.nameAndTypeIndex = 0

    def readInfo(self, clsReader):
        self.bootMethodAttrIndex = int.from_bytes(clsReader.readU16(), "big")
        self.nameAndTypeIndex = cint.from_bytes(clsReader.readU16(), "big")

